define(['common/js/boss-frame-angular-dev-0.1', 'common/js/service/boss-common-option-service'], function () {
    diretiveModule.directive('projectEventSelect', function () {
        return {
            scope: false,
            restrict: "E",
            replace: true,
            transclude: true,
            controller: function ($scope) {
                $scope.changeEvent = function (params) {
                    $scope.$broadcast("reload-eventId", params);
                };

            },
            template: function (tElem, tAttrs) {
                var str1 = '', str2 = '';
                //如果是门店或者分销端
                if (tAttrs.outlet == "true") {
                    str1 += 'checked-index="1"';
                    str2 += 'checked-index="1"';
                }


                return '<tmp>\n    <grid-condition-select class="mr10"\n             ' + str1 + '              condition-name="projectId"\n                           condition-type="select"\n                           condition-tip="项目名称"\n                           cut-length="10"\n                           service-name="SelectCommonOptionService" service-method="projectList"\n                           select-key="id"\n                           change-do="changeEvent"\n              option-condition="myCondition"\n                           select-value="text"></grid-condition-select>\n\n    <grid-condition-select class="mr10"\n             ' + str2 + '              condition-name="eventId"\n                           condition-type="select"\n                           condition-tip="场次名称"\n                           service-name="SelectCommonOptionService" service-method="queryEventsByIdText"\n                           change-do="changeDoFn"\n                           broadcast="true"\n                           cut-length="10"\n                           select-key="id"\n                           select-value="text"></grid-condition-select>\n</tmp>'
            },
            compile: function (tElem, tAttrs) {
                //如果是门店或者分销端
                if (tAttrs.outlet == "true") {
                    tElem.find("grid-condition-select[condition-name='projectId']").attr("checked-index", "1");
                    tElem.find("grid-condition-select[condition-name='eventId']").attr("checked-index", "1");
                }

                return {
                    post: function (scope, elem, attrs) {
                        var eventChangeDoStr = attrs.eventChangeDo;

                        scope.changeDoFn = function (eventIdText) {
                            if (!eventChangeDoStr) return;

                            scope[eventChangeDoStr]({
                                eventId: eventIdText.id,
                                eventName: eventIdText.text
                            });
                        };
                    }
                };
            }
        };
    });

});